<?php 
/**
* @author Oliver Leisalu, Inditel Meedia
* @package DomFg
* @subpackage Input
*/
class DomFgCheckBox extends DomFgInput {
	
	protected $checked;
	
	protected $value = 1;
	
	public function __construct( $name = NULL, $checked = NULL ) {
		parent::__construct( $name );
		$this->checked( $checked );
	}
	
	public function checked( $checked ) {
		$this->checked = (bool)$checked;
		return $this;
	}
	
	public function value( $value ) {
		$this->value = $value;
	} 
	
	private static function getReturnValue( $value ) {
		if( is_array($value) ) {
			foreach( $value as &$v) {
				$v = self::getReturnValue( $v );
			}
			return $value;
		} else {
			if( $value == 0 or $value == 1 )
				return (bool)$value;
			else
				return (string)$value;
		}
	}

	public static function parsePost( $name, &$value ) {
		return self::getReturnValue( $value );
		
	}
	
	public function render() {
		$renderer = $this->getRenderer();
		$renderer->assign('input', $this );
		return $renderer->fetch('Input/CheckBox.html');
	}
	

}
?>